from blog.models import *
import datetime
from django.conf import settings

def needed_js(request):
    """
    Find out what JS plugins we need and add them to the needed_js list.

    This list will be iterated in the base.html template in order to include all
    needed javascript files near the end of the website - so that geting them is
    the "least important" thing the webbrowser has to download.
    """
    jsfld = settings.MEDIA_URL + 'js/'

    needed = [
        jsfld + 'ui.core.js',
        ]

    if(not request.is_ajax()):#no need to care about JS loading if we just want to get/post some data by ajax querys
        if(request.path == '/' or request.path.startswith('/widgets')
           or request.path.startswith('/pulpit')):
            needed.append(jsfld + 'ui.sortable.js') #widget sorting
            needed.append(jsfld + 'jquery.editinplace.packed.js')#edit in place

    return {
        'needed_js': needed,
    }
